package com.zhangliuliu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhangliuliu.bean.DiseaseBean;
import com.zhangliuliu.dao.DiseaseDao;
import com.zhangliuliu.service.DiseaseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class DiseaseServiceImpl extends ServiceImpl<DiseaseDao, DiseaseBean> implements DiseaseService {
    @Override
    public void add(DiseaseBean diseaseBean) {
        save(diseaseBean);
    }

    @Override
    public DiseaseBean find(int id) {
        return getById(id);
    }

    @Override
    public IPage<DiseaseBean> cutByItem(int pageNo, int pageSize, String name, String disease) {
         Page<DiseaseBean> Page = new Page<>(pageNo, pageSize);
         QueryWrapper wrapper = new QueryWrapper();
         if (name!=null &&!name.equals("")){
             wrapper.eq("dis_name",name);
         }
         if (disease!=null&& !disease.equals("")){
             wrapper.eq("disease",disease);
         }
       IPage<DiseaseBean> iPage= this.page(Page,wrapper);
        return iPage;
    }

    @Override
    public IPage<DiseaseBean> cut(int pageNo, int pageSize, String name, String harm, String regular) {
        Page<DiseaseBean> Page = new Page<>(pageNo, pageSize);
        QueryWrapper wrapper = new QueryWrapper();
        if (name!=null&&!name.equals("")){
            wrapper.eq("dis_name",name);
        }
        if (harm!=null&&!harm.equals("")){
            wrapper.eq("dis_harm",harm);
        }
        if (regular!=null&&!regular.equals("")){
            wrapper.eq("regular",regular);
        }
        return this.page(Page,wrapper);
    }
}
